input.test.js ➔ ... ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 1
c 5
b 0
f 0
nc 1
dl 0
loc 1
rs 10
nop 0
1
const inputHelper = require('../../helper/input')
2
3
describe('Input helper', () => {
4
  const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
5
6
  it('input is a file path', () => {
7
    const mockCallback = jest.fn()
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
8
    inputHelper('src/test/sample.html', mockCallback)
9
    expect(mockCallback.mock.calls.length).toBe(1)
10
    expect(mockCallback.mock.calls[0][0]).toMatchSnapshot()
11
  })
12
13
  it('input is a not existed file path', () => {
14
    const mockCallback = jest.fn()
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
15
    inputHelper('src/test/dummy.html', mockCallback)
16
    expect(spy).toHaveBeenCalled()
17
    expect(mockCallback.mock.calls.length).toBe(0)
18
    expect(spy.mock.calls[0][0]).toContain('Cannot read file')
19
  })
20
21
  it('input is a read stream', done => {
22
    const Readable = require('stream').Readable
23
    const readable = new Readable()
24
    const mockCallback = jest.fn(() => {})
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
    readable._read = () => {}
26
    readable.push('streamData 1')
27
    readable.push('streamData 2')
28
    readable.push('streamData 3')
29
    inputHelper(readable, mockCallback)
30
    setTimeout(() => {
31
      try {
32
        expect(mockCallback.mock.calls[0][0]).toBe('streamData 1')
33
        expect(mockCallback.mock.calls[1][0]).toBe('streamData 2')
34
        expect(mockCallback.mock.calls[2][0]).toBe('streamData 3')
35
        done()
36
      } catch (err) {
37
        done.fail(err)
38
      }
39
    }, 2000)
40
  })
41
42
  it('input is invalid', () => {
43
    inputHelper(null)
44
    expect(spy).toHaveBeenCalled()
45
    expect(spy.mock.calls[1][0]).toContain('Invalid Input')
46
  })
47
})
48